"""
Author : sunshicheng
DateTime : 2021/5/18.9:31 上午
FileName : locust_fasthttpuser.py
Desc: 
"""
from locust import TaskSet, task, constant
from locust.contrib.fasthttp import FastHttpUser
import sys

sys.path.append('..')
from config.base_info import Static_info as si
from config.user_token import Token

"""
FastHttpUser
使用gevent协程

method 请求方式
path 接口路径
get 方式，所有的参数只能拼接在url中
其他不变，继承的user类变成fast

"""

token = Token('18226287291')
headers = token.test_token()


class My_task(TaskSet):
    @task
    def test_get(self):
        inter = si.inter['saas']['saas_permission'] + '?account=sunshicheng'
        with self.client.request(method='GET', path=inter, headers=headers, name='fastHttpUser 获取用户权限 ',
                                 catch_response=True) as result:
            # result = self.client.request(method='GET', path=inter, headers=headers, name='fastHttpUser 获取用户权限 ')
            if '"code":0' in result.text:
                result.success()
            else:
                # 错误信息可以自己定义
                print(result.text)
                result.failure('failure')

    def test_post(self):
        date = {}
        result = self.client.request(method='POST', path='', name='', data=date)
        print(result.text)


class Fast_http(FastHttpUser):
    tasks = [My_task]
    wait_time = constant(0.1)
